package com.jmail.sample;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.skn.constant.Constant;
import com.swtdesigner.SWTResourceManager;

public class LoginDialog extends Dialog {

	protected Object result;
	protected Shell shell;

	private Text txtUsername;
	private Text txtPassword;
	private Combo cmbMailHost;
	
	private String[] lstMailHost;
	private String[] lstMailHostDisp;
	
	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public LoginDialog(Shell parent, int style) {
		super(parent, style);
		setText("Sign In");
		
		createContents();
		
		init();
		
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), getStyle());
		shell.setSize(515, 363);
		shell.setText(getText());

		Label lblUserName = new Label(shell, SWT.NONE);
		lblUserName.setBounds(125, 84, 68, 13);
		lblUserName.setText("User name:");
		
		txtUsername = new Text(shell, SWT.BORDER);
		txtUsername.setBounds(199, 81, 180, 19);
		
		txtPassword = new Text(shell, SWT.BORDER);
		txtPassword.setBounds(199, 120, 180, 19);
		
		Label lblPassword = new Label(shell, SWT.NONE);
		lblPassword.setText("Password:");
		lblPassword.setBounds(125, 123, 68, 13);
		
		Label lblMailHost = new Label(shell, SWT.NONE);
		lblMailHost.setText("Mail host:");
		lblMailHost.setBounds(125, 162, 68, 13);
		
		cmbMailHost = new Combo(shell, SWT.NONE);
		cmbMailHost.setBounds(199, 159, 180, 21);
		
		Button btnSignIn = new Button(shell, SWT.NONE);
		btnSignIn.setBounds(199, 193, 84, 23);
		btnSignIn.setText("Sign In");
		
		Label label = new Label(shell, SWT.NONE);
		label.setImage(SWTResourceManager.getImage(Login.class, "/com/jmail/images/email1_120x101.png"));
		label.setBounds(10, 10, 128, 93);
		
		Label label_1 = new Label(shell, SWT.NONE);
		label_1.setImage(SWTResourceManager.getImage(Login.class, "/com/jmail/images/Email5_110x110.png"));
		label_1.setBounds(195, 230, 128, 93);
		
		Label label_2 = new Label(shell, SWT.NONE);
		label_2.setImage(SWTResourceManager.getImage(Login.class, "/com/jmail/images/email7_110x80.png"));
		label_2.setBounds(397, 0, 110, 93);
		
		Label label_3 = new Label(shell, SWT.NONE);
		label_3.setImage(SWTResourceManager.getImage(Login.class, "/com/jmail/images/Email6_110x110.png"));
		label_3.setBounds(369, 181, 128, 126);
		
		Label label_4 = new Label(shell, SWT.NONE);
		label_4.setImage(SWTResourceManager.getImage(Login.class, "/com/jmail/images/email8_110x110.png"));
		label_4.setBounds(10, 181, 137, 117);
	}

	private void init() {
		lstMailHost = new String[] {Constant.HOST_GMAIL, Constant.HOST_YAHOO_MAIL};
		lstMailHostDisp = new String[] {"GMail", "Yahoo Mail"};
		
		this.cmbMailHost.setItems(lstMailHostDisp);
	}
}
